//
//  UPDbManager.m
//
//  Created by admin on 16/1/21.
//  Copyright © 2016年 . All rights reserved.
//

#import "UPDbManager.h"


@interface UPDbManager ()
@property (nonatomic,strong) FMDatabase *db;
@end

@implementation UPDbManager
static id _instance;

+(instancetype)allocWithZone:(struct _NSZone *)zone
{
    if (_instance==nil) {
       static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _instance=[super allocWithZone:zone];
        });
    }
    return _instance;
}
+(instancetype)sharedManager
{
    if (_instance==nil) {
        _instance=[[self alloc] init];
    }
    return _instance;
}
-(FMDatabase *)db
{
    if (_db==nil) {
        //设置sqlite数据文件的路径
        NSString *path=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"onemail.db"];
        //创建一个管理sqlite数据库的对象
        _db=[FMDatabase databaseWithPath:path];
        
        //打开数据库
        [_db open];
        NSString *search=@"create table if not exists search (sid integer primary key autoincrement,stext text not null)";
        [_db executeUpdate:search];
    }
    return _db;
}
/**
 *  执行，增删改操作
 */
-(void)executeUpdate:(NSString *)sql;
{
    [self.db executeUpdate:sql];
}
/**
 *  执行查询操作
 */
-(FMResultSet *)executeQuery:(NSString *)select
{
    return [self.db executeQuery:select];
}


@end












